package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.ImageTools;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;

/**
 * Created by Administrator on 2017/2/20.
 * 商家收款
 */

public class BusinessRcvMoney extends BaseActivity {
    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private ImageView img_back, img_erweima;
    private RelativeLayout rly_save_erweima;
    private ScrollView sv_business;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.business_rcvmonry);
        mActivity = this;
        init();
    }

    private void init() {
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        myApplication = MyApplication.getInstance();

        img_erweima = (ImageView) mActivity.findViewById(R.id.img_erweima);
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        sv_business = (ScrollView) mActivity.findViewById(R.id.sv_business);

        ImageLoader.getInstance().displayImage(myApplication.getDataEntity().getStore_qrcode(), img_erweima, displayImageOptions);

        //保存二维码
        rly_save_erweima = (RelativeLayout) mActivity.findViewById(R.id.rly_save_erweima);
        rly_save_erweima.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                ImageTools.saveImageToGallery(mActivity, takeScreenShot());//保存图片
            }
        });
    }


    private Bitmap takeScreenShot() {
        // View是你需要截图的View
        View view = getWindow().getDecorView();
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap obtainBitmap = view.getDrawingCache();

        // 获取状态栏高度
        Rect frame = new Rect();
        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        int statusBarHeight = frame.top;
        Log.e("ssss", "statusBarHeight==>" + statusBarHeight);
        // 获取屏幕长和高
        int width = getWindowManager().getDefaultDisplay().getWidth();
        int height = getWindowManager().getDefaultDisplay().getHeight();

        // 截取当前屏幕，去掉标题栏
        Bitmap bitmap = Bitmap.createBitmap(obtainBitmap, 0, statusBarHeight + 100, width, height
                - statusBarHeight - 100);

        view.destroyDrawingCache();
        view.setDrawingCacheEnabled(false);

        return bitmap;
    }


}
